/*
 * Copyright (C) 2007-2008  Hylke van der Schaaf
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, in version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
package hextd;

import hextd.core.ContextListener;
import hextd.UI.*;
import hextd.blackBox.BlackBox;
import hextd.core.MapLoaderClient;
import hextd.core.ContextNormal;
import hextd.core.ContextPlayer;
import hextd.hex.*;
import hextd.message.MessageChannelJoin;
import hextd.message.MessageReplayLogSP;
import hextd.message.MessageSettings;
import hextd.creep.Creep;
import hextd.core.MapInfo;
import hextd.core.gameloop.GameLoopImplementation;
import hextd.core.gameloop.GameLoopManager;
import hextd.tower.*;
import hextd.util.*;
import hextd.wave.*;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JApplet;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.StyleSheet;

/**
 *
 * @author hylke
 */
public class HexTD extends javax.swing.JApplet implements ContextListener {

	public static final String NAME = "Hex Tower Defence ";
	public static final String VERSION = "TD.net-0.10.21";
	public static final boolean debug = true;

	public static enum Direction {

		NORTH,
		EAST,
		SOUTH,
		WEST,
		UP,
		DOWN,
		LEFT,
		RIGHT
	}

	public static enum GameState {

		titleScreen(false),
		mpConnect(false),
		mpSelecting(true),
		mpClientSelecting(true),
		mpPlaying(true),
		mpGameEnd(true),
		mpWatching(true),
		mpChecking(false),
		mpJoinRunning(true),
		mpCatchup(true),
		spSelecting(false),
		spPlaying(false),
		spPlayingWaveless(false),
		spGameEnd(false),
		editing(false),
		loadReplay(false),
		replaying(false),
		checking(false),
		checkingEnd(false);
		public boolean hasNetwork;
		public GameLoopImplementation gameLoop;
		private static GameLoopImplementation nullLoop;

		private GameState(boolean hasNetwork) {
			this.hasNetwork = hasNetwork;
		}
	}

	public static enum GameResult {

		inactive,
		loading,
		waitingForMap,
		badMap,
		active,
		won,
		lost,
		ended
	}
	//
	private GameBoard gameBoard;
	private GameLoopManager gameLoop;
	private Keymap keyMap = new Keymap();
	//
	private ContextNormal context;
	private MapLoaderClient mapLoader;
	private BlackBox blackBoxRecord;
	private BlackBox blackBoxPlayback;
	//
	private boolean autoLaunch = false;
	private boolean placingTower = false;
	private TowerFactory.type placingTowerType;
	private float placingTowerRange = 0;
	private Hex highlightedHex;
	private int lastMouseX = 0;
	private int lastMouseY = 0;
	private PanelTowerSettingsHomeBase homeTowerPanel;
	//
	private static DecimalFormat form = new DecimalFormat("#,##0.00");
	private HTMLEditorKit editorkit;
	//
	private URL replayFetchUrl;
	private String mode;
	private String serverAddress = "localhost";
	private int serverPort = 4567;
	private String token = "PlayerX";
	private MessageReplayLogSP scoreMessage;
	//
	private int[] skipValues = {25, 10, 5, 2, 1};
	private int skipMode = 1;
	private String status = null;
	private Timer delayTimer;
	private boolean destroyed = false;

	/** Creates a new instance of NewJApplet */
	@Override
	public void init() {
		System.out.println(HexTD.NAME + " v" + HexTD.VERSION);

		try {
			UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
		} catch (ClassNotFoundException ex) {
			Logger.getLogger(HexTD.class.getName()).log(Level.SEVERE, null, ex);
		} catch (InstantiationException ex) {
			Logger.getLogger(HexTD.class.getName()).log(Level.SEVERE, null, ex);
		} catch (IllegalAccessException ex) {
			Logger.getLogger(HexTD.class.getName()).log(Level.SEVERE, null, ex);
		} catch (UnsupportedLookAndFeelException ex) {
			Logger.getLogger(HexTD.class.getName()).log(Level.SEVERE, null, ex);
		}

		try {
			mode = ParameterUtils.paramToString(this, "mode", "play");
			replayFetchUrl = new URL(ParameterUtils.paramToUrl(this, "replayFetchUrl", "http://localhost/"));
			System.out.println("HexTD::init: scoreFetchUrl=" + replayFetchUrl);
		} catch (MalformedURLException ex) {
			Logger.getLogger(HexTD.class.getName()).log(Level.SEVERE, null, ex);
		}
		serverAddress = ParameterUtils.paramToString(this, "serverAddress", serverAddress);
		System.out.println("HexTD: serverAddress: " + serverAddress);
		serverPort = ParameterUtils.paramToInt(this, "serverPort", serverPort);
		System.out.println("HexTD: serverPort: " + serverPort);
		token = ParameterUtils.paramToString(this, "token", token);
		System.out.println("HexTD: token: " + token);

		context = new ContextNormal(this);
		context.setContextUrl(getClass().getResource("/hextd/"));

		context.addContextListener(this);
		context.addWaveStartListener(new WaveStartListener() {

			@Override
			public void waveStarted() {
				jButton_nextWave.setEnabled(false);
				setWavePreview();
			}
		});
		gameBoard = new GameBoard(this, this.context);
		context.setGameBoard(gameBoard);

		gameBoard.addMouseListener(new java.awt.event.MouseAdapter() {

			@Override
			public void mouseClicked(java.awt.event.MouseEvent evt) {
				mouseClickedBoard(evt);
			}
		});
		gameBoard.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {

			@Override
			public void mouseMoved(java.awt.event.MouseEvent evt) {
				mouseMovedBoard(evt);
			}
		});

		blackBoxRecord = new BlackBox(this.context);
		blackBoxPlayback = new BlackBox(this.context);
		context.setBlackBox(blackBoxRecord);
		gameLoop = new GameLoopManager(context, blackBoxPlayback, blackBoxRecord);
		context.setGameLoop(gameLoop);

		try {
			SwingUtilities.invokeAndWait(new Runnable() {

				@Override
				public void run() {
					localComponents();
				}
			});
		} catch (InterruptedException ex) {
			Logger.getLogger(HexTD.class.getName()).log(Level.SEVERE, null, ex);
		} catch (InvocationTargetException ex) {
			Logger.getLogger(HexTD.class.getName()).log(Level.SEVERE, null, ex);
		}

		delayTimer = new Timer("delayTimer", true);
		jLabelGameTitle.setTimer(delayTimer);

		mapLoader.loadlocalIndex("maps/levels.txt", context.getContextUrl());
		if (mode.equalsIgnoreCase("watch")) {
			// We are reviewing a topscore
			System.out.println("HexTD: Watch mode.");
			context.setGameState(HexTD.GameState.loadReplay);

			setUI();

			jPanelNetConnection.setServerAddress(serverAddress, serverPort);
			Boolean mpReplay = ParameterUtils.paramToBool(this, "mpReplay", false);
			int replayId = ParameterUtils.paramToInt(this, "replayId", 0);
			jPanelNetConnection.loadReplay(mpReplay, replayId);
		} else {
			// Normal game
			System.out.println("HexTD: Game mode");
			context.setGameState(HexTD.GameState.titleScreen);
			jPanelNetConnection.setServerAddress(serverAddress, serverPort);

		}
		setUI();

		this.invalidate();
		this.validate();
	}

	public void loadReplay(String replayLog) {
		context.getGameTime().reset();
		blackBoxPlayback.loadLog(replayLog);
		context.setGameState(HexTD.GameState.replaying);
		if (context.getGameResult() != GameResult.waitingForMap) {
			startReplay();
		}
	}

	public void startReplay() {
		context.setGameResult(GameResult.active);

		gameBoard.recalculateScale();
		gameBoard.startPaintTimer();

		gameLoop.startGameLoop();
	}

	private void localComponents() {
		initComponents();
		jLabel1.setVisible(false);
		jLabel2.setVisible(false);
		jLabel24.setVisible(false);
		jLabel25.setVisible(false);

		context.colors = this.colors;
		mapLoader = new MapLoaderClient(jPanelNetConnection);
		context.setMapLoader(mapLoader);

		jPanelNetConnection.setVisible(false);
		jPanelNetConnection.setContext(context);
		jPanelNetConnection.setToken(token);
		jPanelConsoleWaveInfo.setContext(context);
		jPanelConsoleLevelSelector.setContext(context, this, mapLoader);
		jPanelConsoleTowerSelector.doInit(context, this);
		jPanelConsoleTowerInfo.setContext(context);
		jPanelConsoleReplayControls.setContext(context, this);
		jPanelConsoleChannelList.add(jPanelNetConnection.getChannelList());
		jPanelConsoleReplayControls.setBlackBox(blackBoxRecord, blackBoxPlayback);
		jPanelConsoleEditor.setContext(context);
		jLabel_debug.setVisible(HexTD.debug);
		jPanelPlay.add(gameBoard, BorderLayout.CENTER);

		fixSize();

		StyleSheet s = context.loadStyleSheet("styles.css");
		editorkit = new HTMLEditorKit();
		editorkit.setStyleSheet(s);
		jTextPaneLevelInfo.setEditorKit(editorkit);
		jInternalFrameMapInfo.setVisible(false);
	}

	public String getStatusMessage() {
		ContextNormal c = context;
		if (c != null) {
			return "<h1>Shortcut keys</h1>" + "<p>" + "<b>p</b>: Pause<br>" + "<b>h</b>: Fast-Forward<br>" + "<b>+</b>/<b>-</b>: Faster/Slower Fast-Forward<br>" + "<b>S</b>: Sell (<b>Y</b>es/<b>N</b>o)<br>" + "<b>u</b>: Upgrade<br>" + "<b>n</b>: Next Wave<br>" + "<b>t</b>: Next Targeting mode<br>" + "</p>" + "<h1>Interest</h1>" + "<p>Interest is " + c.getInterestStart() + "% plus " + c.getInterestIncrease() + "% per unspend bonus point.</p>" + "<h1>Upgrades</h1>" + "<p>Upgrades increase damage with 45% and range with 7%.</p>";
		} else {
			return "";
		}
	}

	public void setDebug(String string) {
		jLabel_debug.setText(string);
	}

	public void setFps(float fps) {
		jLabelFps.setText("fps: " + form.format(fps));
	}

	public void setInfoText(String s, boolean forced) {
		if (jPanelConsoleTowerInfo.hasSelectedTower() && !forced) {
			return;
		}
		unSelectTower();
		jPanelConsoleTowerInfo.setExternalText(s);
	}

	public void enemyDied(int enemiesLeft) {
		if (enemiesLeft == 0 && context.getWave() < context.getWaveCount()) {
			System.out.println("HexTD::enemyDied: " + context.getGameTime() + " Last enemy died.");
			context.setWaveReady(true);
			context.setWaveActive(false);
			if (context.getGameState() == GameState.spPlaying) {
				if (autoLaunch) {
					context.setStartWave(true);
				} else {
					jButton_nextWave.setEnabled(true);
				}
			}
		} else if (enemiesLeft == 0 && context.getWave() >= context.getWaveCount()) {
			context.setWaveActive(false);
			context.setGameResult(GameResult.won);
			context.setGameState(GameState.spGameEnd);
			gameOver();
		}
	}

	public void setWavePreview() {
		jPanelConsoleWaveInfo.clearWaves();
		int wave = this.context.getWave();
		ArrayList<Wave> waves = this.context.getWaves();
		if (wave - 1 >= 0) {
			jPanelConsoleWaveInfo.setWaveCur(waves.get(wave - 1));
		}
		if (wave < waves.size()) {
			jPanelConsoleWaveInfo.setWaveNext(waves.get(wave));
		}
	}

	public void updateInfo() {
		ContextPlayer player = this.context.getLocalPlayer();
		if (player != null) {
			player.waveChanged("" + this.context.getWave() + "/" + this.context.getWaveCount());
		}
	}

	public void setHomeBasePanel(PanelTowerSettings p) {
		jPanelConsoleHomeTowerPanel.removeAll();
		jPanelConsoleHomeTowerPanel.add(p);
		if (p instanceof PanelTowerSettingsHomeBase) {
			homeTowerPanel = (PanelTowerSettingsHomeBase) p;
		}
	}

	public void removeHomeBasePanel() {
		jPanelConsoleHomeTowerPanel.removeAll();
	}

	@Override
	public void moneyChanged(ContextPlayer player) {
		if (player == this.context.getLocalPlayer()) {
			this.updateInfo();
		}
	}

	@Override
	public void livesChanged(ContextPlayer player) {
		if (player == this.context.getLocalPlayer()) {
			this.updateInfo();
//			if (player.getLives() <= 0) {
//				this.gameOver();
//			}
		}
	}

	@Override
	public void interestChanged(ContextPlayer player) {
		if (player == this.context.getLocalPlayer()) {
			this.updateInfo();
		}
	}

	public void gameOver() {
		gameLoop.stopGameLoop();
		this.gameLoop.endMaxGameSpeed();

		ContextPlayer player = this.context.getLocalPlayer();
		if (player != null) {
			jLabelFinalScore.setText("" + player.getScore());
			if (!context.isConnected()) {
				System.out.println("HexTD::gameOver: Connecting to server...");
				jPanelNetConnection.startClient();
			}

			// Prepare a score message so we can send it later.
			try {
				scoreMessage = new MessageReplayLogSP(
						context.getWave(),
						player.getScore(),
						Integer.parseInt(context.getMapLocation()),
						blackBoxRecord.printLog().toString(),
						jCheckBox_replayPublic.isSelected(),
						jTextField_postUserName.getText());
			} catch (NumberFormatException e) {
				System.out.println("HexTD::gameOver: No mapId?");
			}
		}
		switch (context.getGameResult()) {
			case won:
				if (context.loadedGameMap.storyWin.length() > 0) {
					setLevelInfo(context.loadedGameMap.storyWin);
				} else {
					jInternalFrameMapInfo.setVisible(false);
				}
				break;
			case lost:
				if (context.loadedGameMap.storyLos.length() > 0) {
					setLevelInfo(context.loadedGameMap.storyLos);
				} else {
					jInternalFrameMapInfo.setVisible(false);
				}
				break;
		}
		setUI();
	}

	public void mapChanged() {
		if (context.loadedGameMap.story.length() > 0) {
			setLevelInfo(context.loadedGameMap.story);
		} else {
			jInternalFrameMapInfo.setVisible(false);
		}
		jPanelConsoleLevelSelector.setLevelInfo(
				"<h1>" + context.loadedGameMap.title + "</h1>" + context.loadedGameMap.info);
		jCheckBox_autoLaunch.setSelected(false);
		gameLoop.resetGraceTicks();
		setStatusPanels();
		updateInfo();
		jPanelConsoleTowerSelector.mapChanged();
		jPanelConsoleEditor.mapChanged();
		repaint();
	}

	public void startLevel(boolean loadmap) {
		System.out.println("HexTD::startLevel");
		gameBoard.stopPaintTimer();
		gameLoop.stopGameLoop();
		jCheckBox_autoLaunch.setSelected(false);

		if (loadmap) {
			blackBoxRecord.clear();
			blackBoxRecord.startMap(context.getMapLocation());
		}

		setWavePreview();
		context.setWaveReady(true);
		gameLoop.resetGraceTicks();
		if (context.getGameResult() != GameResult.waitingForMap) {
			context.setGameResult(GameResult.active);
		}
		MapInfo mapInfo;
		switch (context.getGameState()) {
			case spSelecting:
			case spGameEnd:
			case spPlaying:
			case replaying:
			case checking:
			case checkingEnd:
			case editing:
				mapInfo = context.getMapInfo();
				if (mapInfo != null) {
					if (mapInfo.waves > 0) {
						context.setGameState(GameState.spPlaying);
					} else {
						context.setGameState(GameState.spPlayingWaveless);
					}
				} else {
					System.err.println("HexTD::startLevel: Map not loaded yet.");
				}
				break;
			case mpJoinRunning:
				mapInfo = context.getMapInfo();
				if (mapInfo != null) {
					if (context.getLocalPlayerId() < context.getMapInfo().players) {
						System.out.println("HexTD::startLevel: " + context.getLocalPlayerId() + " < " + context.getMapInfo().players + " thus catchup.");
						context.setGameState(GameState.mpCatchup);
					} else {
						System.out.println("HexTD::startLevel: " + context.getLocalPlayerId() + " > " + context.getMapInfo().players + " thus watching.");
						context.setGameState(GameState.mpWatching);
					}
				} else {
					System.err.println("HexTD::startLevel: Map not loaded yet.");
				}
				break;
			default:
				if (context.getLocalPlayerId() < context.getActivePlayers()) {
					context.setGameState(GameState.mpPlaying);
				} else {
					context.setGameState(GameState.mpWatching);
				}
				break;
		}
		setUI();
		setStatusPanels();
		unSelectTower();
		gameLoop.startGameLoop();
		gameBoard.startPaintTimer();
	}

	public void reStartLevel() {
		gameLoop.stopGameLoop();
		if (gameLoop.isRunning()) {
			System.out.println("HexTD::reStartLevel: Waiting for gameLoop to stop.");
			TimerTask startLevelTask = new TimerTask() {

				@Override
				public void run() {

					reStartLevel();
				}
			};
			delayTimer.schedule(startLevelTask, 100l);
			return;
		} else {
			startLevel(true);
		}
	}

	public void nextLevel() {
		if (context.loadedMapInfo != null) {
			int mapId = context.loadedMapInfo.nextMap;
			MapInfo map = mapLoader.getMap(mapId);
			if (mapId != 0 && map != null) {
				context.loadMap(map, "");
				context.setGameState(GameState.spSelecting);
			}
		}
	}

	public void maxGameSpeed(boolean on) {
		if (on) {
			this.gameLoop.setMaxGameSpeed();
		} else {
			this.gameLoop.endMaxGameSpeed();
		}
	}

	private void setStatusPanels() {
		jPanelConsoleGameInfo.removeAll();
		PanelStatusSinglePlayer pssp;
		PanelStatusMultiPlayer psmp;
		ContextPlayer p;

		ContextNormal c = context;
		if (c != null) {
			switch (c.getGameState()) {
				case spPlaying:
					p = c.getLocalPlayer();
					if (p != null) {
						pssp = p.getStatusPanelSinglePlayer();
						updateInfo();
						jPanelConsoleGameInfo.add(pssp);
					}
					break;

				case mpPlaying:
				case spPlayingWaveless:
					jPanelNetConnection.updatePlayerNames();
					int lpid = c.getLocalPlayerId();
					p = c.getLocalPlayer();
					if (p != null) {
						psmp = p.getStatusPanelMultiPlayer();
						psmp.setTitle(p.getPlayerName(), c.colors.getColorPlayers()[lpid]);
						jPanelConsoleGameInfo.add(psmp);
					}
					break;

				case mpWatching:
				case mpChecking:
					jPanelNetConnection.updatePlayerNames();
					int pc = c.getActivePlayers();
					for (int i = 0; i < pc; i++) {
						p = c.getPlayer(i);
						psmp = p.getStatusPanelMultiPlayer();
						psmp.setTitle(p.getPlayerName(), c.colors.getColorPlayers()[i]);
						jPanelConsoleGameInfo.add(psmp);
					}
					break;
				case replaying:
				case checking:
					pc = c.getActivePlayers();
					if (pc > 1) {
						for (int i = 0; i < pc; i++) {
							p = c.getPlayer(i);
							psmp = p.getStatusPanelMultiPlayer();
							psmp.setTitle(p.getPlayerName(), c.colors.getColorPlayers()[i]);
							jPanelConsoleGameInfo.add(psmp);
						}
					} else {
						p = c.getPlayer(0);
						pssp = p.getStatusPanelSinglePlayer();
						jPanelConsoleGameInfo.add(pssp);
					}
					break;
			}
		}
	}

	private void setGameButtons() {
		boolean bNextWave = false;
		boolean bAutoLaunch = false;
		boolean bFastforward = false;
		boolean bPause = false;

		switch (this.context.getGameState()) {
			case editing:
				jCheckBox_autoLaunch.setSelected(false);
				break;

			case checking:
				bFastforward = true;
				bPause = true;
				break;

			case mpPlaying:
			case mpWatching:
			case spPlayingWaveless:
				bFastforward = true;
				bPause = true;
				break;

			case spPlaying:
				bNextWave = true;
				if (!context.isWaveActive() && !this.autoLaunch) {
					jButton_nextWave.setEnabled(true);
				} else {
					jButton_nextWave.setEnabled(false);
				}
				bAutoLaunch = true;
				jCheckBox_autoLaunch.setEnabled(true);
				bFastforward = true;
				break;

			default:
				break;
		}

		jButton_nextWave.setVisible(bNextWave);
		jCheckBox_autoLaunch.setVisible(bAutoLaunch);
		jCheckBoxPause.setVisible(bPause);
		jCheckBox_fastForward.setVisible(bFastforward);


	}

	private void setMenu() {
		switch (context.getGameState()) {
			case mpPlaying:
				jMenuItem_ReplayCenter.setEnabled(true);
				jMenuItem_editLevel.setEnabled(false);
				jMenuItem_exitLevel.setEnabled(false);
				jMenuItem_restartLevel.setEnabled(false);
				break;

			case spPlaying:
				jMenuItem_ReplayCenter.setEnabled(true);
				jMenuItem_editLevel.setEnabled(true);
				jMenuItem_exitLevel.setEnabled(true);
				jMenuItem_restartLevel.setEnabled(true);
				break;

			case checking:
				jMenuItem_ReplayCenter.setEnabled(false);
				jMenuItem_editLevel.setEnabled(false);
				jMenuItem_exitLevel.setEnabled(false);
				jMenuItem_restartLevel.setEnabled(false);
				break;

			case replaying:
				jMenuItem_ReplayCenter.setEnabled(false);
				jMenuItem_editLevel.setEnabled(false);
				jMenuItem_exitLevel.setEnabled(true);
				jMenuItem_restartLevel.setEnabled(true);
				break;
			case editing:
				jMenuItem_ReplayCenter.setEnabled(false);
				jMenuItem_editLevel.setEnabled(false);
				jMenuItem_exitLevel.setEnabled(true);
				jMenuItem_restartLevel.setEnabled(true);
				break;
			default:
				jMenuItem_ReplayCenter.setEnabled(true);
				jMenuItem_editLevel.setEnabled(true);
				jMenuItem_exitLevel.setEnabled(false);
				jMenuItem_restartLevel.setEnabled(false);
				break;
		}
		jCheckBoxMenuItem_quality.setEnabled(!jCheckBoxMenuItemAutoQuality.isSelected());
	}

	public void setUI() {
		if (!SwingUtilities.isEventDispatchThread()) {
			SwingUtilities.invokeLater(new Runnable() {

				@Override
				public void run() {
					setUI();
				}
			});
		} else {
			setStatus(null);
			ContextNormal ct = context;
			if (destroyed) {
				System.err.println("HexTD::SetUI: called after destroyed");
				System.err.println(Thread.currentThread().getStackTrace());
			} else {
				jLabelConnectionStatus1.setText(jPanelNetConnection.getStatus());
				jLabelConnectionStatus2.setText(jPanelNetConnection.getStatus());
				setGameButtons();
				setMenu();

				boolean PanelMapEnds = false;
				boolean PanelNetConnection = false;
				boolean PanelSubmits = false;
				boolean PanelPlay = false;
				boolean PanelConsole = false;
				boolean PanelConsoleEditor = false;
				boolean PanelConsoleGameInfo = false;
				boolean PanelConsoleLevelSelector = false;
				boolean PanelConsoleTowerInfo = false;
				boolean PanelConsoleTowerSelector = false;
				boolean PanelConsoleWaveInfo = false;
				boolean PanelConsoleHomeTowerPanel = false;
				boolean PanelConsoleReplayControls = false;
				boolean PanelConsoleChannelList = false;
				boolean PanelBadMap = false;

				boolean internalFrameLevelInfo = false;

				boolean PanelGameStarts = false;
				boolean ButtonMPEnabled = false;
				boolean ButtonSP = false;
				boolean ButtonReconnect = false;
				boolean gameBoardVisible = false;
				boolean paintFast = true;

				boolean Panel_GameWon = false;
				boolean Panel_GameLost = false;
				boolean Button_wonNextMap = false;
				boolean ButtonWonLobby = false;
				boolean Panel_replayEnded = false;
				boolean Button_lostTryAgain = false;
				boolean ButtonLostLobby = false;
				boolean keepTextBar = true;

				switch (ct.getGameState()) {
					case titleScreen:
						gameBoard.stopPaintTimer();

						PanelGameStarts = true;
						ButtonMPEnabled = (ct.getAuthenticated() == ContextNormal.AuthStatus.success);
						ButtonReconnect = (ct.getAuthenticated() != ContextNormal.AuthStatus.success);
						ButtonSP = true;
						break;

					case mpConnect:
						PanelConsole = true;
						PanelConsoleChannelList = true;
						PanelGameStarts = true;
						PanelNetConnection = true;
						break;

					case mpSelecting:
						gameBoardVisible = true;
						PanelNetConnection = true;
						PanelPlay = true;
						PanelConsole = true;
						PanelConsoleChannelList = true;
						PanelConsoleLevelSelector = true;
						jPanelConsoleLevelSelector.setEnabled(true);
						if (context.loadedGameMap != null && context.loadedGameMap.story.length() > 0) {
							internalFrameLevelInfo = true;
						}
						paintFast = false;
						break;

					case mpClientSelecting:
						gameBoardVisible = true;
						PanelNetConnection = true;
						PanelPlay = true;
						PanelConsole = true;
						PanelConsoleChannelList = true;
						PanelConsoleLevelSelector = true;
						jPanelConsoleLevelSelector.setEnabled(false);
						paintFast = false;
						break;

					case mpPlaying:
						gameBoardVisible = true;
						PanelNetConnection = true;
						PanelPlay = true;
						PanelConsole = true;
						PanelConsoleChannelList = true;
						PanelConsoleGameInfo = true;
						setStatusPanels();
						PanelConsoleTowerSelector = true;
						jPanelConsoleTowerInfo.setExternalText(this.getStatusMessage());
						PanelConsoleHomeTowerPanel = true;
						jLabelGameTitle.setForeground(ct.colors.getColorPlayers()[ct.getLocalPlayerId()]);
						keepTextBar = true;
						break;

					case mpJoinRunning:
					case mpWatching:
						gameBoardVisible = true;

						PanelNetConnection = true;
						PanelPlay = true;
						PanelConsole = true;
						PanelConsoleChannelList = true;
						PanelConsoleGameInfo = true;
						setStatusPanels();
						jPanelConsoleTowerInfo.setExternalText(this.getStatusMessage());
						jLabelGameTitle.setForeground(ct.colors.getColorForeGround());
						break;
					case mpGameEnd:
						PanelMapEnds = true;
						switch (ct.getGameResult()) {
							case won:
								Panel_GameWon = true;
								ButtonWonLobby = true;
								PanelNetConnection = true;
								break;
							case lost:
								Panel_GameLost = true;
								ButtonLostLobby = true;
								PanelNetConnection = true;
								break;
						}
						break;
					case spSelecting:
						PanelConsole = true;
						PanelConsoleLevelSelector = true;
						jPanelConsoleLevelSelector.setEnabled(true);
						if (context.getGameResult() == GameResult.badMap) {
							PanelBadMap = true;
						} else {
							gameBoardVisible = true;
							PanelPlay = true;
							if (context.loadedGameMap != null && context.loadedGameMap.story.length() > 0) {
								internalFrameLevelInfo = true;
							}
						}
						paintFast = false;
						break;

					case spPlaying:
						gameBoardVisible = true;
						PanelPlay = true;
						PanelConsole = true;
						PanelConsoleGameInfo = true;
						setStatusPanels();
						PanelConsoleTowerSelector = true;
						PanelConsoleWaveInfo = true;
						jPanelConsoleTowerInfo.setExternalText(this.getStatusMessage());
						break;

					case spPlayingWaveless:
						gameBoardVisible = true;
						PanelPlay = true;
						PanelConsole = true;
						PanelConsoleChannelList = true;
						PanelConsoleGameInfo = true;
						setStatusPanels();
						PanelConsoleTowerSelector = true;
						jPanelConsoleTowerInfo.setExternalText(this.getStatusMessage());
						PanelConsoleHomeTowerPanel = true;
						break;

					case spGameEnd:
						jButton_postScore.setEnabled(true);
						jLabel_submitFeedback.setText("");
						PanelMapEnds = true;
						switch (ct.getGameResult()) {
							case lost:
								Panel_GameLost = true;
								Button_lostTryAgain = true;
								if (context.loadedGameMap != null && context.loadedGameMap.storyLos.length() > 0) {
									internalFrameLevelInfo = true;
								}
								break;
							case won:
								Panel_GameWon = true;
								if (context.loadedGameMap != null && context.loadedMapInfo.nextMap != 0) {
									Button_wonNextMap = true;
								}
								if (context.loadedGameMap != null && context.loadedGameMap.storyWin.length() > 0) {
									internalFrameLevelInfo = true;
								}
								break;
						}
						if (!ct.getMapLocation().equals("Custom")) {
							PanelSubmits = true;
							if (ct.getAuthenticated() == ContextNormal.AuthStatus.success) {
								jTextField_postUserName.setText(jPanelNetConnection.getPlayerName());
								jTextField_postUserName.setEnabled(false);
							} else {
								jTextField_postUserName.setText("PlayerX");
								jTextField_postUserName.setEnabled(true);
							}
							if (ct.isConnected()) {
								jButton_postScore.setEnabled(true);
							} else {
								jButton_postScore.setEnabled(false);
							}
						}
						break;

					case replaying:
					case checking:
						switch (ct.getGameResult()) {
							case active:
								PanelPlay = true;
								gameBoardVisible = true;
								PanelConsole = true;
								PanelConsoleGameInfo = true;
								setStatusPanels();
								PanelConsoleWaveInfo = true;
								PanelConsoleReplayControls = true;
								break;
							case ended:
								Panel_replayEnded = true;
								break;
						}
						break;

					case mpChecking:
						switch (ct.getGameResult()) {
							case active:
								PanelPlay = true;
								gameBoardVisible = true;
								PanelConsole = true;
								PanelConsoleGameInfo = true;
								setStatusPanels();
								PanelConsoleReplayControls = true;
								break;
							case ended:
								Panel_replayEnded = true;
								break;
						}
						break;

					case editing:
						// TODO: When starting editing, copy MapInfo into MapInfo for mapId=0 and load that MapInfo.
						//ct.setMapLocation("Custom");
						PanelPlay = true;
						gameBoardVisible = true;
						PanelConsole = true;
						PanelConsoleEditor = true;
						paintFast = false;
						break;

				}

				jPanelMapEnds.setVisible(PanelMapEnds);
				jPanelNetConnection.setVisible(PanelNetConnection);
				jPanelNetConnection.setKeepTextBar(keepTextBar);
				jPanelSubmits.setVisible(PanelSubmits);
				jPanelPlay.setVisible(PanelPlay);
				jPanelConsole.setVisible(PanelConsole);
				jPanelConsoleEditor.setVisible(PanelConsoleEditor);
				jPanelConsoleGameInfo.setVisible(PanelConsoleGameInfo);
				jPanelConsoleLevelSelector.setVisible(PanelConsoleLevelSelector);
				jPanelConsoleTowerInfo.setVisible(PanelConsoleTowerInfo);
				jPanelConsoleTowerSelector.setVisible(PanelConsoleTowerSelector);
				jPanelConsoleWaveInfo.setVisible(PanelConsoleWaveInfo);
				jPanelConsoleHomeTowerPanel.setVisible(PanelConsoleHomeTowerPanel);
				jPanelConsoleReplayControls.setVisible(PanelConsoleReplayControls);
				jPanelConsoleChannelList.setVisible(PanelConsoleChannelList);

				jPanelGameStarts2.setVisible(PanelGameStarts);
				jButtonMP.setEnabled(ButtonMPEnabled);
				jButtonSP.setEnabled(ButtonSP);
				jButtonReconnect.setEnabled(ButtonReconnect);
				jButtonReconnect1.setEnabled(ButtonReconnect);
				jPanelConsoleChannelList.setVisible(PanelConsoleChannelList);
				jPanelBadMap.setVisible(PanelBadMap);

				gameBoard.setVisible(gameBoardVisible);
				gameBoard.setSlow(!paintFast);
				if (gameBoardVisible) {
					this.validate();
					gameBoard.recalculateScale();
					gameBoard.startPaintTimer();
				}

				jPanel_GameWon.setVisible(Panel_GameWon);
				jPanel_GameLost.setVisible(Panel_GameLost);
				jButton_wonNextMap.setVisible(Button_wonNextMap);
				jButtonWonLobby.setVisible(ButtonWonLobby);
				jButtonWonChoose.setVisible(!ButtonWonLobby);
				jPanel_replayEnded.setVisible(Panel_replayEnded);
				jButtonLostTryAgain.setVisible(Button_lostTryAgain);
				jButtonLostLobby.setVisible(ButtonLostLobby);
				jButtonLostChoose.setVisible(!ButtonLostLobby);

				jInternalFrameMapInfo.setVisible(internalFrameLevelInfo);
			}
		}
	}

	public void startPlacing(TowerFactory.type t, float r) {
		placingTower = true;
		placingTowerType = t;
		placingTowerRange = r;
		Hex h = gameBoard.hexFromScreenCoords(lastMouseX, lastMouseY);
		highLightHex(h);
	}

	public void unSelectTower() {
		unHighLighHex();
		jPanelConsoleTowerInfo.unselectTower();
		jPanelConsoleTowerInfo.setExternalText(this.getStatusMessage());
	}

	public void unHighLighHex() {
		if (!destroyed) {
			if (highlightedHex != null) {
				highlightedHex.setHighlight(Hex.highlightType.none);
			}
		}
		highlightedHex = null;
	}

	public void highLightHex(Hex h, Hex.highlightType t) {
		unHighLighHex();
		h.setHighlight(t);
		highlightedHex = h;
	}

	public void highLightHex(Hex h) {
		unHighLighHex();
		if (h != null) {
			highlightedHex = h;
			if (context.getGameState() == HexTD.GameState.editing) {
				h.setHighlight(Hex.highlightType.editHex);
			} else if (placingTower) {
				h.setHighlight(Hex.highlightType.placeTower);
				h.setHighlightRange(placingTowerRange);
			}
		}
	}

	public static void main(String s[]) {
		JFrame f = new JFrame("HexTD");
		f.addWindowListener(new WindowAdapter() {

			@Override
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
		JApplet applet = new HexTD();
		f.getContentPane().add("Center", applet);
		applet.init();
		f.pack();
		f.setSize(new Dimension(800, 600));
		f.setVisible(true);
	}

	public void setQuality(boolean high) {
		jCheckBoxMenuItem_quality.setSelected(high);
		gameBoard.setQualityHigh(high);
	}

	public void togglePause() {
		this.setPause(!this.gameLoop.isPaused(), true);
	}

	private void reDisplayTitle() {
		if (this.status == null) {
			if (this.gameLoop.isPaused()) {
				jLabelGameTitle.setText("        Paused         ");
				jLabelGameTitle.startBlinking();
			} else {
				jLabelGameTitle.setText(HexTD.NAME);
				jLabelGameTitle.stopBlinking();
			}
		} else {
			jLabelGameTitle.setText(this.status);
			jLabelGameTitle.startBlinking();
		}
	}

	public void setPause(boolean p, boolean transmit) {
		if (gameLoop.isPaused() != p) {
			gameLoop.setPaused(p);
			jCheckBoxPause.setSelected(p);
			reDisplayTitle();
			if (transmit) {
				jPanelNetConnection.sendLine(MessageSettings.formatMessageSingle(-1, MessageSettings.settingKey.pause, Boolean.toString(p)));
			}
		}
	}

	public void setStatus(String text) {
		status = text;
		reDisplayTitle();
	}

	private void changeHex(Keymap.MappableAction to) {
		if (this.highlightedHex != null) {
			switch (to) {
				case makeHexEmpty:
					context.getGameGrid().changeHex(highlightedHex.getLocation(), HexEmpty.key);
					break;
				case makeHexNormal:
					context.getGameGrid().changeHex(highlightedHex.getLocation(), HexBase.key);
					break;
				case makeHexPath:
					context.getGameGrid().changeHex(highlightedHex.getLocation(), HexPath.key);
					break;
				case makeHexTransparent:
					context.getGameGrid().changeHex(highlightedHex.getLocation(), HexTransparent.key);
					break;
			}

			this.gameBoard.recalculateScale();
		}
	}

	private void mouseClicked(int button, int screenx, int screeny) {
		Hex hex = gameBoard.hexFromScreenCoords(screenx, screeny);

		boolean keepPlacing = false;
		jPanelConsoleTowerInfo.unselectTower();
		switch (context.getGameState()) {
			case spPlaying:
			case spPlayingWaveless:
			case mpPlaying:
				jPanelConsoleTowerInfo.setExternalText(this.getStatusMessage());
		}

		unHighLighHex();
		if (hex != null) {
			int[] location = hex.getLocation();
			int col = location[0];
			int row = location[1];
			if (this.context.getGameState() == HexTD.GameState.editing) {
				jPanelConsoleEditor.hexClicked(hex);
			} else {
				if (this.placingTower) {
					switch (button) {
						case MouseEvent.BUTTON1:
							this.context.newTower(col, row, this.placingTowerType);
							this.placingTower = false;
							jPanelConsoleTowerSelector.stopPlacing();
							break;

						case MouseEvent.BUTTON3:
							this.context.newTower(col, row, this.placingTowerType);
							keepPlacing = true;
							break;

						case MouseEvent.BUTTON2:
							this.context.newTower(col, row, this.placingTowerType);
							Tower newTower = hex.getTower();
							ContextPlayer player = this.context.getLocalPlayer();
							if (newTower != null) {
								while (newTower.canUpgrade() && player.canPay(newTower.getUpgradePrice(true), true)) {
									this.context.upgradeTower(newTower);
								}

							}
							keepPlacing = true;
							break;

					}
				}
				switch (this.context.getGameState()) {
					case spPlaying:
					case spPlayingWaveless:
					case mpPlaying:
					case mpWatching:
					case mpChecking:
					case replaying:
					case checking:
						if (hex.hasTower()) {
							jPanelConsoleTowerInfo.setTower(hex.getTower());
							this.highLightHex(hex, Hex.highlightType.selectTower);
							if (button == MouseEvent.BUTTON2) {
								Tower newTower = hex.getTower();
								ContextPlayer player = context.getLocalPlayer();
								if (newTower != null) {
									while (newTower.canUpgrade() && player.canPay(newTower.getUpgradePrice(true), true)) {
										this.context.upgradeTower(newTower);
									}

								}
							}
						} else {
							Creep es = this.context.findClosestCreep(screenx, screeny, gameBoard.getPaintScale());
							if (es != null) {
								jPanelConsoleTowerInfo.setCreep(es);
							}
						}
						break;

				}
			}
			return;
		}
		if (placingTower && !keepPlacing) {
			placingTower = false;
			jPanelConsoleTowerSelector.stopPlacing();
			unHighLighHex();
		}

	}

	private void mouseClickedBoard(java.awt.event.MouseEvent evt) {
		mouseClicked(evt.getButton(), evt.getX(), evt.getY());
	}

	private void mouseMovedBoard(java.awt.event.MouseEvent evt) {
		gameBoard.requestFocusInWindow();
		lastMouseX = evt.getX();
		lastMouseY = evt.getY();
		if (placingTower || context.getGameState() == HexTD.GameState.editing) {
			Hex h = gameBoard.hexFromScreenCoords(lastMouseX, lastMouseY);
			if (placingTower || context.getGameState() == HexTD.GameState.editing) {
				highLightHex(h);
			}

		}
	}

	public void keyTyped(char key) {
		//System.out.println("HexTD::keyTyped: " + key);
		Keymap.MappableGameState state = Keymap.MappableGameState.watching;
		switch (this.context.getGameState()) {
			case editing:
				state = Keymap.MappableGameState.editing;
				break;
			case spPlaying:
			case spPlayingWaveless:
			case mpPlaying:
				state = Keymap.MappableGameState.playing;
				break;

		}
		Keymap.MappableAction action = keyMap.getAction(state, key);
		if (action == null) {
			return;
		}

		if (jPanelConsoleTowerInfo.isSelling() && action != Keymap.MappableAction.confirm) {
			jPanelConsoleTowerInfo.cancelSell();
		}

		switch (action) {
			case startTextInput:
				System.out.println("showing text input bar");
				jPanelNetConnection.showTextBar();
				break;
			case makeHexEmpty:
			case makeHexNormal:
			case makeHexPath:
			case makeHexTransparent:
				this.changeHex(action);
				break;

			case buyCreeps:
				if (homeTowerPanel != null) {
					homeTowerPanel.doSendCreeps();
				}
				break;

			case fastForwardToggle:
				this.gameLoop.toggleGameSpeed();
				jCheckBox_fastForward.setSelected(this.gameLoop.isFastForward());
				break;

			case callNextWave:
				this.context.nextWave();
				break;

			case pauseToggle:
				this.togglePause();
				break;

			case confirm:
				if (jPanelConsoleTowerInfo.isSelling()) {
					jPanelConsoleTowerInfo.confirmSell();
				}
				break;

			case sellSelectedTower:
				jPanelConsoleTowerInfo.startSellCurrentTower();
				break;

			case targetModeUp:
				jPanelConsoleTowerInfo.nextMode(1, 1);
				break;
			case targetModeDown:
				jPanelConsoleTowerInfo.nextMode(1, -1);
				break;

			case toggleLock:
				jPanelConsoleTowerInfo.nextMode(0, 1);
				break;

			case upgrade:
				jPanelConsoleTowerInfo.upgradeCurrentTower(false);
				break;

			case upgradeFull:
				jPanelConsoleTowerInfo.upgradeCurrentTower(true);
				break;

			// Creep-count hotkeys
			case creepCountToggle:
				if (homeTowerPanel != null) {
					if (homeTowerPanel.getMode(3) > 1) {
						homeTowerPanel.setMode(3, 1, false);
					} else {
						homeTowerPanel.setMode(3, 10, false);
					}
				}
				break;

			case creepCountDown:
				if (homeTowerPanel != null) {
					homeTowerPanel.nextMode(3, -1);
				}
				break;
			case creepCountUp:
				if (homeTowerPanel != null) {
					homeTowerPanel.nextMode(3, 1);
				}
				break;

			// Creep-sizes hotkeys
			case creepSizeDown:
				if (homeTowerPanel != null) {
					homeTowerPanel.nextMode(2, -1);
				}
				break;
			case creepSizeUp:
				if (homeTowerPanel != null) {
					homeTowerPanel.nextMode(2, 1);
				}
				break;

			// Creep-health hotkeys
			case creepHealthDown:
				if (homeTowerPanel != null) {
					homeTowerPanel.nextMode(5, -1);
				}
				break;
			case creepHealthUp:
				if (homeTowerPanel != null) {
					homeTowerPanel.nextMode(5, 1);
				}
				break;

			// Creep type
			case creepTypeDown:
				if (homeTowerPanel != null) {
					homeTowerPanel.nextMode(1, -1);
				}
				break;
			case creepTypeUp:
				if (homeTowerPanel != null) {
					homeTowerPanel.nextMode(1, 1);
				}
				break;

			// Paths
			case pathDown:
				if (homeTowerPanel != null) {
					homeTowerPanel.nextMode(4, -1);
				}
				break;
			case pathUp:
				if (homeTowerPanel != null) {
					homeTowerPanel.nextMode(4, 1);
				}
				break;


			// Tower-build hotkeys
			case buildTowerGreen1:
				jPanelConsoleTowerSelector.doPlace(0);
				break;
			case buildTowerRed1:
				jPanelConsoleTowerSelector.doPlace(1);
				break;
			case buildTowerYellow1:
				jPanelConsoleTowerSelector.doPlace(2);
				break;
			case buildTowerBlue1:
				jPanelConsoleTowerSelector.doPlace(3);
				break;
			case buildTowerGreen2:
				jPanelConsoleTowerSelector.doPlace(5);
				break;
			case buildTowerRed2:
				jPanelConsoleTowerSelector.doPlace(6);
				break;
			case buildTowerYellow2:
				jPanelConsoleTowerSelector.doPlace(7);
				break;
			case buildTowerBlue2:
				jPanelConsoleTowerSelector.doPlace(8);
				break;
			case buildTowerGreen3:
				jPanelConsoleTowerSelector.doPlace(10);
				break;
			case buildTowerRed3:
				jPanelConsoleTowerSelector.doPlace(11);
				break;
			case buildTowerYellow3:
				jPanelConsoleTowerSelector.doPlace(12);
				break;
			case buildTowerBlue3:
				jPanelConsoleTowerSelector.doPlace(13);
				break;


			case cancel:
				if (placingTower) {
					placingTower = false;
					jPanelConsoleTowerSelector.stopPlacing();
					unHighLighHex();
				}

				break;
			case fastForwardUp:
				this.ffPlus();
				break;

			case fastForwardDown:
				this.ffMin();
				break;

		}
	}

	private void ffPlus() {
		if (this.skipMode < this.skipValues.length - 1) {
			this.skipMode++;
		}

		int curSkip = this.skipValues[this.skipMode];
		this.gameLoop.setTickTimeFast(curSkip);
		int times = 50 / curSkip;
		jCheckBox_fastForward.setText("FF (" + times + "x)");

	}

	private void ffMin() {
		if (this.skipMode > 0) {
			this.skipMode--;
		}

		int curSkip = this.skipValues[this.skipMode];
		gameLoop.setTickTimeFast(curSkip);
		int times = 50 / curSkip;
		jCheckBox_fastForward.setText("FF (" + times + "x)");
	}

	public void showAlert(String alert) {
		if (!SwingUtilities.isEventDispatchThread()) {
			final String localAlert = alert;
			SwingUtilities.invokeLater(new Runnable() {

				@Override
				public void run() {
					showAlert(localAlert);
				}
			});
		} else {
			JOptionPane.showMessageDialog(this,
					alert,
					"Alert!",
					JOptionPane.WARNING_MESSAGE);
		}
	}

	public void setLevelInfo(String info) {
		jTextPaneLevelInfo.setText(info);
		jInternalFrameMapInfo.setVisible(true);
		int w = gameBoard.getWidth();
		int h = gameBoard.getHeight();
		jInternalFrameMapInfo.setLocation(w / 4, h / 4);
		jInternalFrameMapInfo.setSize(w / 2, h / 2);
	}

	public void goToReplayCentre() {
		gameLoop.stopGameLoop();
		gameBoard.stopPaintTimer();
		if (context.isConnected()) {
			context.messageSend(MessageChannelJoin.formatMessage(-1));
		}
		context.setGameState(GameState.replaying);
		context.setGameResult(GameResult.active);
		blackBoxPlayback.copyFrom(this.blackBoxRecord);
		blackBoxRecord.clear();
		context.getGameTime().reset();

		gameBoard.startPaintTimer();
		gameLoop.startGameLoop();
		gameLoop.setPauseAtTick(1);
		setUI();
	}

	private void postScore() {
		jButton_postScore.setEnabled(false);

		// Update the score message and send it to the server.
		if (context.isConnected() && scoreMessage != null) {
			ContextPlayer player = this.context.getLocalPlayer();
			scoreMessage.setPublic(jCheckBox_replayPublic.isSelected());
			scoreMessage.setUserName(jTextField_postUserName.getText());
			context.messageSend(scoreMessage.getMessage());
		}
	}

	@Override
	public void start() {
		super.start();
		System.out.println("HexTD::start: Starting.");
	}

	@Override
	public void stop() {
		System.out.println("HexTD::stop: Stopping.");
		switchExternal(false);
		gameLoop.stopGameLoop();
		jPanelNetConnection.stop();
	}

	@Override
	public void destroy() {
		destroyed = true;
		switchExternal(false);
		jPanelNetConnection.stop();
		gameBoard.stopPaintTimer();
		gameBoard.cleanup();
		delayTimer.cancel();
		jPanelConsoleWaveInfo.cleanUp();
		context.cleanup();
		context = null;
		gameLoop = null;
		gameBoard = null;
		blackBoxPlayback = null;
		blackBoxRecord = null;
		System.out.println("HexTD::destroy: Exiting.");
	}

	/**
	 * Puts the game full-screen, or back in the browser.
	 * @param external true for fullscreen.
	 */
	private void switchExternal(boolean external) {
		jToggleButtonFullScreen.setSelected(external);
		jCheckBoxMenuItem_external.setSelected(external);
		if (external) {
			this.remove(jPanel_gamePanel);
			this.add(jPanel_externalMessage);
			jFrame_fullscreen.add(jPanel_gamePanel);
			jFrame_fullscreen.setVisible(true);
			jFrame_fullscreen.setExtendedState(Frame.MAXIMIZED_BOTH);
			this.gameBoard.recalculateScale();
			this.invalidate();
			this.validate();
			this.repaint();
		} else {
			this.remove(jPanel_externalMessage);
			this.add(jPanel_gamePanel);
			jFrame_fullscreen.remove(jPanel_gamePanel);
			jFrame_fullscreen.setVisible(false);
			this.invalidate();
			this.validate();
			this.repaint();
			this.gameBoard.recalculateScale();
		}

	}

	private void fixSize() {
		SwingUtilities.invokeLater(new Runnable() {

			@Override
			public void run() {
				validate();
				int width = getWidth();
				int height = getHeight();
				jPanel_gamePanel.setSize(width, height);
				repaint();
			}
		});

	}

	private void gotoMainMenu() {
		if (jPanelNetConnection.optionalForfeitGame()) {
			gameLoop.stopGameLoop();
			gameBoard.stopPaintTimer();
			if (context.isConnected()) {
				context.messageSend(MessageChannelJoin.formatMessage(-1));
			}
			context.setGameState(GameState.titleScreen);
			context.setGameResult(GameResult.inactive);
		}
	}

	private void gotoSpLevelSelection() {
		if (jPanelNetConnection.optionalForfeitGame()) {
			gameLoop.stopGameLoop();
			gameBoard.stopPaintTimer();
			if (context.isConnected()) {
				context.messageSend(MessageChannelJoin.formatMessage(-1));
			}
			context.setGameState(HexTD.GameState.spSelecting);
			jCheckBox_autoLaunch.setSelected(false);
			autoLaunch = false;
			context.resetWaves();
			context.removeAllEnemies();
			context.clearTowers();
			setUI();
		}
	}

	/** This method is called from within the init() method to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        colors = new hextd.util.colorSelection();
        jPopupMenu = new javax.swing.JPopupMenu();
        jMenuItemHome = new javax.swing.JMenuItem();
        jMenuItem_restartLevel = new javax.swing.JMenuItem();
        jMenuItem_exitLevel = new javax.swing.JMenuItem();
        jMenuItem_editLevel = new javax.swing.JMenuItem();
        jMenuItem_ReplayCenter = new javax.swing.JMenuItem();
        jCheckBoxMenuItem_background = new javax.swing.JCheckBoxMenuItem();
        jCheckBoxMenuItem_quality = new javax.swing.JCheckBoxMenuItem();
        jCheckBoxMenuItemAutoQuality = new javax.swing.JCheckBoxMenuItem();
        jCheckBoxMenuItem_external = new javax.swing.JCheckBoxMenuItem();
        jMenuItemKeymap = new javax.swing.JMenuItem();
        jFrame_fullscreen = new javax.swing.JFrame();
        jPanel_externalMessage = new javax.swing.JPanel();
        jButton3 = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jFrameKeymap = new javax.swing.JFrame();
        jScrollPaneKeymap = new javax.swing.JScrollPane();
        jTextPane_outputKeymap = new javax.swing.JTextPane();
        jButtonLoadKeymap = new javax.swing.JButton();
        jLayeredPaneMain = new javax.swing.JLayeredPane();
        jPanel_gamePanel = new javax.swing.JPanel();
        jPanelGameButtons = new javax.swing.JPanel();
        jButton_nextWave = new javax.swing.JButton();
        jButton_menu = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();
        jLabel_debug = new javax.swing.JLabel();
        jLabelGameTitle = new hextd.util.BlinkingLabel();
        jLabelFps = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jCheckBox_autoLaunch = new javax.swing.JCheckBox();
        jCheckBoxPause = new javax.swing.JCheckBox();
        jCheckBox_fastForward = new javax.swing.JCheckBox();
        jPanel_board = new javax.swing.JPanel();
        jPanelNetConnection = new hextd.UI.PanelNetConnection();
        jPanelGameStarts2 = new hextd.util.ImagePanel();
        jLabel24 = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jButtonSP = new javax.swing.JButton();
        jButtonMP = new javax.swing.JButton();
        jButtonReconnect = new javax.swing.JButton();
        jLabelConnectionStatus1 = new javax.swing.JLabel();
        jToggleButtonFullScreen = new javax.swing.JToggleButton();
        jLabelVersion = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jPanelMapEnds = new javax.swing.JPanel();
        jPanel_GameLost = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        jButtonLostTryAgain = new javax.swing.JButton();
        jButtonLostReplay = new javax.swing.JButton();
        jButtonLostLobby = new javax.swing.JButton();
        jButtonLostChoose = new javax.swing.JButton();
        jButtonLostMain = new javax.swing.JButton();
        jPanel_GameWon = new javax.swing.JPanel();
        jLabel12 = new javax.swing.JLabel();
        jButton_wonNextMap = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jButtonWonLobby = new javax.swing.JButton();
        jButtonWonChoose = new javax.swing.JButton();
        jButtonWonMain = new javax.swing.JButton();
        jPanel_replayEnded = new javax.swing.JPanel();
        jLabel21 = new javax.swing.JLabel();
        jPanelSubmits = new javax.swing.JPanel();
        jLabelConnectionStatus2 = new javax.swing.JLabel();
        jPanel_submitScore = new javax.swing.JPanel();
        jTextField_postUserName = new javax.swing.JTextField();
        jLabel22 = new javax.swing.JLabel();
        jButton_postScore = new javax.swing.JButton();
        jLabel_submitFeedback = new javax.swing.JLabel();
        jCheckBox_replayPublic = new javax.swing.JCheckBox();
        jLabel26 = new javax.swing.JLabel();
        jLabelFinalScore = new javax.swing.JLabel();
        jButtonReconnect1 = new javax.swing.JButton();
        jPanelPlay = new javax.swing.JPanel();
        jPanelBadMap = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jPanelConsole = new javax.swing.JPanel();
        jPanelConsoleWaveInfo = new hextd.UI.PanelWaveInfo();
        jPanelConsoleTowerInfo = new hextd.UI.PanelTowerInfo();
        jPanelConsoleGameInfo = new javax.swing.JPanel();
        jPanelConsoleTowerSelector = new hextd.UI.PanelTowerSelector();
        jPanelConsoleLevelSelector = new hextd.UI.PanelLevelSelector();
        jPanelConsoleReplayControls = new hextd.UI.PanelReplayControls();
        jPanelConsoleHomeTowerPanel = new javax.swing.JPanel();
        jPanelConsoleChannelList = new javax.swing.JPanel();
        jPanelConsoleEditor = new hextd.UI.PanelEditor();
        jInternalFrameMapInfo = new javax.swing.JInternalFrame();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTextPaneLevelInfo = new javax.swing.JTextPane();

        colors.setColorBackGround(new java.awt.Color(40, 45, 50));
        colors.setColorBaseBackGround(new java.awt.Color(0, 0, 0));
        colors.setColorBaseEmptyHexBorder(new java.awt.Color(56, 149, 185));
        colors.setColorBaseHexBackGround(new java.awt.Color(33, 54, 75));
        colors.setColorBaseHexBorder(new java.awt.Color(183, 183, 244));
        colors.setColorForeGround(new java.awt.Color(220, 255, 220));
        colors.setColorForeGroundPale(new java.awt.Color(184, 207, 229));
        colors.setColorHealthLine(new java.awt.Color(0, 199, 0));
        colors.setColorHighlightNOK(new java.awt.Color(255, 0, 0));
        colors.setColorHighlightOK(new java.awt.Color(213, 255, 213));
        colors.setColorOpenBackGround(new java.awt.Color(50, 0, 25));
        colors.setColorRangeCircle(new java.awt.Color(204, 204, 204));

        jPopupMenu.setBackground(colors.getColorBackGround());
        jPopupMenu.setForeground(colors.getColorForeGround());

        jMenuItemHome.setText("Main Menu");
        jMenuItemHome.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemHomeActionPerformed(evt);
            }
        });
        jPopupMenu.add(jMenuItemHome);

        jMenuItem_restartLevel.setBackground(colors.getColorBackGround());
        jMenuItem_restartLevel.setForeground(colors.getColorForeGround());
        jMenuItem_restartLevel.setText("Restart Level");
        jMenuItem_restartLevel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_restartLevelActionPerformed(evt);
            }
        });
        jPopupMenu.add(jMenuItem_restartLevel);

        jMenuItem_exitLevel.setBackground(colors.getColorBackGround());
        jMenuItem_exitLevel.setForeground(colors.getColorForeGround());
        jMenuItem_exitLevel.setText("Level Selection");
        jMenuItem_exitLevel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_exitLevelActionPerformed(evt);
            }
        });
        jPopupMenu.add(jMenuItem_exitLevel);

        jMenuItem_editLevel.setBackground(colors.getColorBackGround());
        jMenuItem_editLevel.setForeground(colors.getColorForeGround());
        jMenuItem_editLevel.setText("Level Editor");
        jMenuItem_editLevel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_editLevelActionPerformed(evt);
            }
        });
        jPopupMenu.add(jMenuItem_editLevel);

        jMenuItem_ReplayCenter.setBackground(colors.getColorBackGround());
        jMenuItem_ReplayCenter.setForeground(colors.getColorForeGround());
        jMenuItem_ReplayCenter.setText("Replay Centre");
        jMenuItem_ReplayCenter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_ReplayCenterActionPerformed(evt);
            }
        });
        jPopupMenu.add(jMenuItem_ReplayCenter);

        jCheckBoxMenuItem_background.setBackground(colors.getColorBackGround());
        jCheckBoxMenuItem_background.setForeground(colors.getColorForeGround());
        jCheckBoxMenuItem_background.setSelected(true);
        jCheckBoxMenuItem_background.setText("Background");
        jCheckBoxMenuItem_background.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jCheckBoxMenuItem_backgroundStateChanged(evt);
            }
        });
        jPopupMenu.add(jCheckBoxMenuItem_background);

        jCheckBoxMenuItem_quality.setBackground(colors.getColorBackGround());
        jCheckBoxMenuItem_quality.setForeground(colors.getColorForeGround());
        jCheckBoxMenuItem_quality.setSelected(true);
        jCheckBoxMenuItem_quality.setText("High Quality");
        jCheckBoxMenuItem_quality.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxMenuItem_qualityActionPerformed(evt);
            }
        });
        jPopupMenu.add(jCheckBoxMenuItem_quality);

        jCheckBoxMenuItemAutoQuality.setBackground(colors.getColorBackGround());
        jCheckBoxMenuItemAutoQuality.setForeground(colors.getColorForeGround());
        jCheckBoxMenuItemAutoQuality.setSelected(true);
        jCheckBoxMenuItemAutoQuality.setText("Auto Quality");
        jCheckBoxMenuItemAutoQuality.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxMenuItemAutoQualityActionPerformed(evt);
            }
        });
        jPopupMenu.add(jCheckBoxMenuItemAutoQuality);

        jCheckBoxMenuItem_external.setBackground(colors.getColorBackGround());
        jCheckBoxMenuItem_external.setForeground(colors.getColorForeGround());
        jCheckBoxMenuItem_external.setText("Escape from Browser");
        jCheckBoxMenuItem_external.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxMenuItem_externalActionPerformed(evt);
            }
        });
        jPopupMenu.add(jCheckBoxMenuItem_external);

        jMenuItemKeymap.setBackground(colors.getColorBackGround());
        jMenuItemKeymap.setForeground(colors.getColorForeGround());
        jMenuItemKeymap.setText("show keymap");
        jMenuItemKeymap.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemKeymapActionPerformed(evt);
            }
        });
        jPopupMenu.add(jMenuItemKeymap);

        jFrame_fullscreen.setMinimumSize(new java.awt.Dimension(400, 350));

        jPanel_externalMessage.setBackground(colors.getColorBackGround());
        jPanel_externalMessage.setForeground(colors.getColorForeGround());
        jPanel_externalMessage.setLayout(new java.awt.GridBagLayout());

        jButton3.setBackground(colors.getColorBackGround());
        jButton3.setForeground(colors.getColorForeGround());
        jButton3.setText("Recover Game");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        jPanel_externalMessage.add(jButton3, gridBagConstraints);

        jLabel7.setBackground(colors.getColorBackGround());
        jLabel7.setForeground(colors.getColorForeGround());
        jLabel7.setText("The game is currently running in external mode.");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        jPanel_externalMessage.add(jLabel7, gridBagConstraints);

        jLabel19.setBackground(colors.getColorBackGround());
        jLabel19.setForeground(colors.getColorForeGround());
        jLabel19.setText("Navigating away from this page will quit the game!");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        jPanel_externalMessage.add(jLabel19, gridBagConstraints);

        jLabel20.setBackground(colors.getColorBackGround());
        jLabel20.setForeground(colors.getColorForeGround());
        jLabel20.setText("Click the button to move the game back to this window.");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        jPanel_externalMessage.add(jLabel20, gridBagConstraints);

        jFrameKeymap.getContentPane().setLayout(new java.awt.GridBagLayout());

        jScrollPaneKeymap.setMinimumSize(new java.awt.Dimension(200, 200));
        jScrollPaneKeymap.setPreferredSize(new java.awt.Dimension(200, 200));
        jScrollPaneKeymap.setViewportView(jTextPane_outputKeymap);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 0.01;
        gridBagConstraints.weighty = 0.01;
        jFrameKeymap.getContentPane().add(jScrollPaneKeymap, gridBagConstraints);

        jButtonLoadKeymap.setText("Load Keymap");
        jButtonLoadKeymap.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonLoadKeymapActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        jFrameKeymap.getContentPane().add(jButtonLoadKeymap, gridBagConstraints);

        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                formComponentResized(evt);
            }
        });

        jLayeredPaneMain.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                jLayeredPaneMainComponentResized(evt);
            }
        });

        jPanel_gamePanel.setBackground(colors.getColorBackGround());
        jPanel_gamePanel.setForeground(colors.getColorForeGround());
        jPanel_gamePanel.setLayout(new java.awt.GridBagLayout());

        jPanelGameButtons.setBackground(colors.getColorBackGround());
        jPanelGameButtons.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createEmptyBorder(1, 2, 2, 1), javax.swing.BorderFactory.createLineBorder(colors.getColorForeGroundPale())));
        jPanelGameButtons.setForeground(colors.getColorForeGround());
        jPanelGameButtons.setFocusable(false);
        jPanelGameButtons.setLayout(new java.awt.GridBagLayout());

        jButton_nextWave.setBackground(colors.getColorBackGround());
        jButton_nextWave.setForeground(colors.getColorForeGround());
        jButton_nextWave.setText("Next Wave");
        jButton_nextWave.setFocusable(false);
        jButton_nextWave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_nextWaveActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
        gridBagConstraints.insets = new java.awt.Insets(2, 5, 2, 5);
        jPanelGameButtons.add(jButton_nextWave, gridBagConstraints);

        jButton_menu.setBackground(colors.getColorBackGround());
        jButton_menu.setForeground(colors.getColorForeGround());
        jButton_menu.setText("Menu");
        jButton_menu.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jButton_menuMousePressed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 0);
        jPanelGameButtons.add(jButton_menu, gridBagConstraints);

        jLabel10.setBackground(colors.getColorBackGround());
        jLabel10.setFont(new java.awt.Font("Dialog", 0, 10));
        jLabel10.setForeground(colors.getColorForeGround());
        jLabel10.setText("v"+this.VERSION);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 4, 0);
        jPanelGameButtons.add(jLabel10, gridBagConstraints);

        jLabel_debug.setBackground(colors.getColorBackGround());
        jLabel_debug.setFont(new java.awt.Font("Dialog", 0, 10));
        jLabel_debug.setForeground(colors.getColorForeGround());
        jLabel_debug.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel_debug.setText("debug");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        jPanelGameButtons.add(jLabel_debug, gridBagConstraints);

        jLabelGameTitle.setBackground(colors.getColorBackGround());
        jLabelGameTitle.setForeground(colors.getColorForeGround());
        jLabelGameTitle.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabelGameTitle.setText(this.NAME);
        jLabelGameTitle.setColor1(colors.getColorForeGround());
        jLabelGameTitle.setColor2(new java.awt.Color(255, 132, 0));
        jLabelGameTitle.setFont(jLabelGameTitle.getFont().deriveFont((jLabelGameTitle.getFont().getStyle() & ~java.awt.Font.ITALIC) | java.awt.Font.BOLD, jLabelGameTitle.getFont().getSize()+5));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 1.0E-4;
        gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 10);
        jPanelGameButtons.add(jLabelGameTitle, gridBagConstraints);

        jLabelFps.setBackground(colors.getColorBackGround());
        jLabelFps.setFont(new java.awt.Font("Dialog", 0, 10));
        jLabelFps.setForeground(colors.getColorForeGround());
        jLabelFps.setText("fps:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 4, 2);
        jPanelGameButtons.add(jLabelFps, gridBagConstraints);

        jPanel2.setBackground(colors.getColorBackGround());
        jPanel2.setForeground(colors.getColorForeGround());
        jPanel2.setLayout(new java.awt.GridBagLayout());

        jCheckBox_autoLaunch.setBackground(colors.getColorBackGround());
        jCheckBox_autoLaunch.setForeground(colors.getColorForeGround());
        jCheckBox_autoLaunch.setText("Auto Launch");
        jCheckBox_autoLaunch.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jCheckBox_autoLaunch.setFocusable(false);
        jCheckBox_autoLaunch.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jCheckBox_autoLaunchStateChanged(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 5);
        jPanel2.add(jCheckBox_autoLaunch, gridBagConstraints);

        jCheckBoxPause.setBackground(colors.getColorBackGround());
        jCheckBoxPause.setForeground(colors.getColorForeGround());
        jCheckBoxPause.setText("Pause");
        jCheckBoxPause.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jCheckBoxPause.setFocusable(false);
        jCheckBoxPause.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxPauseActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 5);
        jPanel2.add(jCheckBoxPause, gridBagConstraints);

        jCheckBox_fastForward.setBackground(colors.getColorBackGround());
        jCheckBox_fastForward.setForeground(colors.getColorForeGround());
        jCheckBox_fastForward.setText("Fast Mode");
        jCheckBox_fastForward.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jCheckBox_fastForward.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jCheckBox_fastForwardStateChanged(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 5);
        jPanel2.add(jCheckBox_fastForward, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 5;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridheight = 2;
        jPanelGameButtons.add(jPanel2, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        jPanel_gamePanel.add(jPanelGameButtons, gridBagConstraints);

        jPanel_board.setBackground(colors.getColorBackGround());
        jPanel_board.setForeground(colors.getColorForeGround());
        jPanel_board.setLayout(new java.awt.GridBagLayout());

        jPanelNetConnection.setBackground(colors.getColorBackGround());
        jPanelNetConnection.setForeground(colors.getColorForeGround());
        jPanelNetConnection.setMaximumSize(new java.awt.Dimension(2147483647, 289));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
        gridBagConstraints.weightx = 0.1;
        jPanel_board.add(jPanelNetConnection, gridBagConstraints);

        jPanelGameStarts2.setBackground(colors.getColorBackGroundDark());
        jPanelGameStarts2.setForeground(colors.getColorForeGround());
        jPanelGameStarts2.setImage(new javax.swing.ImageIcon(getClass().getResource("/hextd/images/HEX-2.png")));
        jPanelGameStarts2.setLayout(new java.awt.GridBagLayout());

        jLabel24.setBackground(colors.getColorBackGroundDark());
        jLabel24.setFont(jLabel24.getFont().deriveFont(jLabel24.getFont().getSize()+7f));
        jLabel24.setForeground(colors.getColorForeGround());
        jLabel24.setText("Hex Tower Defence");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        jPanelGameStarts2.add(jLabel24, gridBagConstraints);

        jLabel25.setBackground(colors.getColorBackGroundDark());
        jLabel25.setFont(jLabel25.getFont().deriveFont(jLabel25.getFont().getSize()+10f));
        jLabel25.setForeground(colors.getColorForeGround());
        jLabel25.setText("Tower Battles");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 10, 0);
        jPanelGameStarts2.add(jLabel25, gridBagConstraints);

        jPanel1.setBackground(colors.getColorBackGroundDark());
        jPanel1.setForeground(colors.getColorForeGround());
        jPanel1.setOpaque(false);
        jPanel1.setLayout(new java.awt.GridBagLayout());

        jButtonSP.setBackground(colors.getColorBackGroundDark());
        jButtonSP.setForeground(colors.getColorForeGround());
        jButtonSP.setText("Single Player");
        jButtonSP.setContentAreaFilled(false);
        jButtonSP.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSPActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.weightx = 0.0010;
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 5, 0);
        jPanel1.add(jButtonSP, gridBagConstraints);

        jButtonMP.setBackground(colors.getColorBackGroundDark());
        jButtonMP.setForeground(colors.getColorForeGround());
        jButtonMP.setText("Multi Player");
        jButtonMP.setContentAreaFilled(false);
        jButtonMP.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonMPActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 5, 0);
        jPanel1.add(jButtonMP, gridBagConstraints);

        jButtonReconnect.setBackground(colors.getColorBackGroundDark());
        jButtonReconnect.setForeground(colors.getColorForeGround());
        jButtonReconnect.setText("↺");
        jButtonReconnect.setToolTipText("Reconnect to Server");
        jButtonReconnect.setContentAreaFilled(false);
        jButtonReconnect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonReconnectActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 0.0010;
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 5, 0);
        jPanel1.add(jButtonReconnect, gridBagConstraints);

        jLabelConnectionStatus1.setBackground(colors.getColorBackGroundDark());
        jLabelConnectionStatus1.setForeground(colors.getColorForeGround());
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 3;
        jPanel1.add(jLabelConnectionStatus1, gridBagConstraints);

        jToggleButtonFullScreen.setBackground(colors.getColorBackGroundDark());
        jToggleButtonFullScreen.setForeground(colors.getColorForeGround());
        jToggleButtonFullScreen.setText("FullScreen");
        jToggleButtonFullScreen.setContentAreaFilled(false);
        jToggleButtonFullScreen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButtonFullScreenActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        jPanel1.add(jToggleButtonFullScreen, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.weighty = 0.01;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        jPanelGameStarts2.add(jPanel1, gridBagConstraints);

        jLabelVersion.setBackground(colors.getColorBackGroundDark());
        jLabelVersion.setForeground(colors.getColorForeGround());
        jLabelVersion.setText(VERSION);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 9;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST;
        gridBagConstraints.weightx = 0.01;
        gridBagConstraints.weighty = 1.0E-7;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 10, 10);
        jPanelGameStarts2.add(jLabelVersion, gridBagConstraints);

        jLabel1.setBackground(colors.getColorBackGroundDark());
        jLabel1.setForeground(colors.getColorForeGroundPale());
        jLabel1.setText("We need a splash screen!");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        jPanelGameStarts2.add(jLabel1, gridBagConstraints);

        jLabel2.setBackground(colors.getColorBackGroundDark());
        jLabel2.setForeground(colors.getColorForeGroundPale());
        jLabel2.setText("Towerdefence.net presents:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanelGameStarts2.add(jLabel2, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 0.01;
        gridBagConstraints.weighty = 0.01;
        jPanel_board.add(jPanelGameStarts2, gridBagConstraints);

        jPanelMapEnds.setBackground(colors.getColorBackGroundDark());
        jPanelMapEnds.setForeground(colors.getColorForeGround());
        jPanelMapEnds.setLayout(new java.awt.GridBagLayout());

        jPanel_GameLost.setBackground(colors.getColorBackGroundDark());
        jPanel_GameLost.setForeground(colors.getColorForeGround());
        jPanel_GameLost.setLayout(new java.awt.GridBagLayout());

        jLabel11.setBackground(colors.getColorBackGroundDark());
        jLabel11.setFont(jLabel11.getFont().deriveFont(jLabel11.getFont().getStyle() | java.awt.Font.BOLD, jLabel11.getFont().getSize()+5));
        jLabel11.setForeground(colors.getColorForeGround());
        jLabel11.setText("Game Over!");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        jPanel_GameLost.add(jLabel11, gridBagConstraints);

        jButtonLostTryAgain.setBackground(colors.getColorBackGroundDark());
        jButtonLostTryAgain.setForeground(colors.getColorForeGround());
        jButtonLostTryAgain.setText("Try Again");
        jButtonLostTryAgain.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonLostTryAgainActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        jPanel_GameLost.add(jButtonLostTryAgain, gridBagConstraints);

        jButtonLostReplay.setBackground(colors.getColorBackGroundDark());
        jButtonLostReplay.setForeground(colors.getColorForeGround());
        jButtonLostReplay.setText("Watch Replay");
        jButtonLostReplay.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonLostReplayActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        jPanel_GameLost.add(jButtonLostReplay, gridBagConstraints);

        jButtonLostLobby.setBackground(colors.getColorBackGroundDark());
        jButtonLostLobby.setForeground(colors.getColorForeGround());
        jButtonLostLobby.setText("Back to Lobby");
        jButtonLostLobby.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonLostLobbyActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        jPanel_GameLost.add(jButtonLostLobby, gridBagConstraints);

        jButtonLostChoose.setBackground(colors.getColorBackGroundDark());
        jButtonLostChoose.setForeground(colors.getColorForeGround());
        jButtonLostChoose.setText("Choose Level");
        jButtonLostChoose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonLostChooseActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        jPanel_GameLost.add(jButtonLostChoose, gridBagConstraints);

        jButtonLostMain.setBackground(colors.getColorBackGroundDark());
        jButtonLostMain.setForeground(colors.getColorForeGround());
        jButtonLostMain.setText("Main Menu");
        jButtonLostMain.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonLostMainActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        jPanel_GameLost.add(jButtonLostMain, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 0.01;
        jPanelMapEnds.add(jPanel_GameLost, gridBagConstraints);

        jPanel_GameWon.setBackground(colors.getColorBackGroundDark());
        jPanel_GameWon.setForeground(colors.getColorForeGround());
        jPanel_GameWon.setLayout(new java.awt.GridBagLayout());

        jLabel12.setBackground(colors.getColorBackGroundDark());
        jLabel12.setFont(jLabel12.getFont().deriveFont(jLabel12.getFont().getStyle() | java.awt.Font.BOLD, jLabel12.getFont().getSize()+5));
        jLabel12.setForeground(colors.getColorForeGround());
        jLabel12.setText("Congratulations!");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        jPanel_GameWon.add(jLabel12, gridBagConstraints);

        jButton_wonNextMap.setBackground(colors.getColorBackGroundDark());
        jButton_wonNextMap.setForeground(colors.getColorForeGround());
        jButton_wonNextMap.setText("Next Map");
        jButton_wonNextMap.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_wonNextMapActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 10, 2);
        jPanel_GameWon.add(jButton_wonNextMap, gridBagConstraints);

        jButton1.setBackground(colors.getColorBackGroundDark());
        jButton1.setForeground(colors.getColorForeGround());
        jButton1.setText("Watch Replay");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        jPanel_GameWon.add(jButton1, gridBagConstraints);

        jButtonWonLobby.setBackground(colors.getColorBackGroundDark());
        jButtonWonLobby.setForeground(colors.getColorForeGround());
        jButtonWonLobby.setText("Back to Lobby");
        jButtonWonLobby.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonWonLobbyActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        jPanel_GameWon.add(jButtonWonLobby, gridBagConstraints);

        jButtonWonChoose.setBackground(colors.getColorBackGroundDark());
        jButtonWonChoose.setForeground(colors.getColorForeGround());
        jButtonWonChoose.setText("Choose Level");
        jButtonWonChoose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonWonChooseActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        jPanel_GameWon.add(jButtonWonChoose, gridBagConstraints);

        jButtonWonMain.setBackground(colors.getColorBackGroundDark());
        jButtonWonMain.setForeground(colors.getColorForeGround());
        jButtonWonMain.setText("Main Menu");
        jButtonWonMain.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonWonMainActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        jPanel_GameWon.add(jButtonWonMain, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 0.01;
        jPanelMapEnds.add(jPanel_GameWon, gridBagConstraints);

        jPanel_replayEnded.setBackground(colors.getColorBackGroundDark());
        jPanel_replayEnded.setForeground(colors.getColorForeGround());
        jPanel_replayEnded.setLayout(new java.awt.GridBagLayout());

        jLabel21.setBackground(colors.getColorBackGroundDark());
        jLabel21.setFont(jLabel21.getFont().deriveFont(jLabel21.getFont().getStyle() | java.awt.Font.BOLD, jLabel21.getFont().getSize()+5));
        jLabel21.setForeground(colors.getColorForeGround());
        jLabel21.setText("Replay Ended");
        jPanel_replayEnded.add(jLabel21, new java.awt.GridBagConstraints());

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 0.01;
        jPanelMapEnds.add(jPanel_replayEnded, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 0.01;
        gridBagConstraints.weighty = 0.01;
        jPanel_board.add(jPanelMapEnds, gridBagConstraints);

        jPanelSubmits.setBackground(colors.getColorBackGroundDark());
        jPanelSubmits.setForeground(colors.getColorForeGround());
        jPanelSubmits.setLayout(new java.awt.GridBagLayout());

        jLabelConnectionStatus2.setBackground(colors.getColorBackGroundDark());
        jLabelConnectionStatus2.setForeground(colors.getColorForeGround());
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
        gridBagConstraints.insets = new java.awt.Insets(10, 0, 5, 0);
        jPanelSubmits.add(jLabelConnectionStatus2, gridBagConstraints);

        jPanel_submitScore.setBackground(colors.getColorBackGroundDark());
        jPanel_submitScore.setForeground(colors.getColorForeGround());
        jPanel_submitScore.setLayout(new java.awt.GridBagLayout());

        jTextField_postUserName.setBackground(colors.getColorBackGroundDark());
        jTextField_postUserName.setColumns(15);
        jTextField_postUserName.setForeground(colors.getColorForeGround());
        jTextField_postUserName.setText("YourName");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
        jPanel_submitScore.add(jTextField_postUserName, gridBagConstraints);

        jLabel22.setBackground(colors.getColorBackGroundDark());
        jLabel22.setForeground(colors.getColorForeGround());
        jLabel22.setText("Submit Score:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
        jPanel_submitScore.add(jLabel22, gridBagConstraints);

        jButton_postScore.setBackground(colors.getColorBackGroundDark());
        jButton_postScore.setForeground(colors.getColorForeGround());
        jButton_postScore.setText("Submit");
        jButton_postScore.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_postScoreActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        jPanel_submitScore.add(jButton_postScore, gridBagConstraints);

        jLabel_submitFeedback.setBackground(colors.getColorBackGroundDark());
        jLabel_submitFeedback.setForeground(colors.getColorForeGround());
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
        gridBagConstraints.weighty = 1.0E-4;
        jPanel_submitScore.add(jLabel_submitFeedback, gridBagConstraints);

        jCheckBox_replayPublic.setBackground(colors.getColorBackGroundDark());
        jCheckBox_replayPublic.setForeground(colors.getColorForeGround());
        jCheckBox_replayPublic.setText("Allow everyone to watch the replay.");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.gridwidth = 2;
        jPanel_submitScore.add(jCheckBox_replayPublic, gridBagConstraints);

        jLabel26.setBackground(colors.getColorBackGroundDark());
        jLabel26.setForeground(colors.getColorForeGround());
        jLabel26.setText("Your Score:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = 2;
        jPanel_submitScore.add(jLabel26, gridBagConstraints);

        jLabelFinalScore.setBackground(colors.getColorBackGroundDark());
        jLabelFinalScore.setFont(jLabelFinalScore.getFont().deriveFont(jLabelFinalScore.getFont().getStyle() | java.awt.Font.BOLD, jLabelFinalScore.getFont().getSize()+6));
        jLabelFinalScore.setForeground(colors.getColorForeGround());
        jLabelFinalScore.setText("00000000");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel_submitScore.add(jLabelFinalScore, gridBagConstraints);

        jButtonReconnect1.setBackground(colors.getColorBackGroundDark());
        jButtonReconnect1.setForeground(colors.getColorForeGround());
        jButtonReconnect1.setText("↺");
        jButtonReconnect1.setToolTipText("Reconnect to Server");
        jButtonReconnect1.setContentAreaFilled(false);
        jButtonReconnect1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonReconnect1ActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanel_submitScore.add(jButtonReconnect1, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
        jPanelSubmits.add(jPanel_submitScore, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 0.01;
        gridBagConstraints.weighty = 0.01;
        jPanel_board.add(jPanelSubmits, gridBagConstraints);

        jPanelPlay.setBackground(colors.getColorBackGroundDark());
        jPanelPlay.setLayout(new java.awt.BorderLayout());
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 0.01;
        gridBagConstraints.weighty = 0.01;
        jPanel_board.add(jPanelPlay, gridBagConstraints);

        jLabel3.setText("Can't play this map yet!");
        jPanelBadMap.add(jLabel3);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 0.01;
        gridBagConstraints.weighty = 0.01;
        jPanel_board.add(jPanelBadMap, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 0.1;
        gridBagConstraints.weighty = 0.1;
        jPanel_gamePanel.add(jPanel_board, gridBagConstraints);

        jPanelConsole.setBackground(colors.getColorBackGround());
        jPanelConsole.setForeground(colors.getColorForeGround());
        jPanelConsole.setFocusable(false);
        jPanelConsole.setMaximumSize(new java.awt.Dimension(200, 2147483647));
        jPanelConsole.setMinimumSize(new java.awt.Dimension(200, 263));
        jPanelConsole.setPreferredSize(new java.awt.Dimension(200, 402));
        jPanelConsole.setLayout(new java.awt.GridBagLayout());

        jPanelConsoleWaveInfo.setBackground(colors.getColorBackGround());
        jPanelConsoleWaveInfo.setForeground(colors.getColorForeGround());
        jPanelConsoleWaveInfo.setName("Current Wave:"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 10;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
        gridBagConstraints.weightx = 0.01;
        gridBagConstraints.weighty = 1.0E-4;
        jPanelConsole.add(jPanelConsoleWaveInfo, gridBagConstraints);

        jPanelConsoleTowerInfo.setBackground(colors.getColorBackGround());
        jPanelConsoleTowerInfo.setForeground(colors.getColorForeGround());
        jPanelConsoleTowerInfo.setFocusable(false);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
        gridBagConstraints.weightx = 1.0E-5;
        gridBagConstraints.weighty = 0.9;
        jPanelConsole.add(jPanelConsoleTowerInfo, gridBagConstraints);

        jPanelConsoleGameInfo.setBackground(colors.getColorBackGround());
        jPanelConsoleGameInfo.setBorder(null);
        jPanelConsoleGameInfo.setForeground(colors.getColorForeGround());
        jPanelConsoleGameInfo.setFocusable(false);
        jPanelConsoleGameInfo.setLayout(new java.awt.GridLayout(0, 1));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
        gridBagConstraints.weightx = 0.01;
        jPanelConsole.add(jPanelConsoleGameInfo, gridBagConstraints);

        jPanelConsoleTowerSelector.setBackground(colors.getColorBackGround());
        jPanelConsoleTowerSelector.setForeground(colors.getColorForeGround());
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 0.01;
        jPanelConsole.add(jPanelConsoleTowerSelector, gridBagConstraints);

        jPanelConsoleLevelSelector.setBackground(colors.getColorBackGround());
        jPanelConsoleLevelSelector.setForeground(colors.getColorForeGround());
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 8;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 0.1;
        gridBagConstraints.weighty = 0.1;
        jPanelConsole.add(jPanelConsoleLevelSelector, gridBagConstraints);

        jPanelConsoleReplayControls.setBackground(colors.getColorBackGround());
        jPanelConsoleReplayControls.setForeground(colors.getColorForeGround());
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        jPanelConsole.add(jPanelConsoleReplayControls, gridBagConstraints);

        jPanelConsoleHomeTowerPanel.setBackground(colors.getColorBackGround());
        jPanelConsoleHomeTowerPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Creep Shop", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 0, 12), colors.getColorForeGround())); // NOI18N
        jPanelConsoleHomeTowerPanel.setForeground(colors.getColorForeGround());
        jPanelConsoleHomeTowerPanel.setLayout(new java.awt.BorderLayout());
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        jPanelConsole.add(jPanelConsoleHomeTowerPanel, gridBagConstraints);

        jPanelConsoleChannelList.setBackground(colors.getColorBackGround());
        jPanelConsoleChannelList.setForeground(colors.getColorForeGround());
        jPanelConsoleChannelList.setLayout(new java.awt.BorderLayout());
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 9;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0E-5;
        gridBagConstraints.weighty = 1.0E-5;
        jPanelConsole.add(jPanelConsoleChannelList, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 0.0010;
        gridBagConstraints.weighty = 1.0E-6;
        jPanelConsole.add(jPanelConsoleEditor, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridheight = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
        gridBagConstraints.weighty = 1.0;
        jPanel_gamePanel.add(jPanelConsole, gridBagConstraints);

        jPanel_gamePanel.setBounds(0, 0, 800, 730);
        jLayeredPaneMain.add(jPanel_gamePanel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jInternalFrameMapInfo.setClosable(true);
        jInternalFrameMapInfo.setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
        jInternalFrameMapInfo.setResizable(true);
        jInternalFrameMapInfo.setTitle("Map Briefing");
        jInternalFrameMapInfo.setVisible(true);

        jScrollPane3.setBorder(null);

        jTextPaneLevelInfo.setBorder(null);
        jScrollPane3.setViewportView(jTextPaneLevelInfo);

        jInternalFrameMapInfo.getContentPane().add(jScrollPane3, java.awt.BorderLayout.CENTER);

        jInternalFrameMapInfo.setBounds(0, 0, 250, 210);
        jLayeredPaneMain.add(jInternalFrameMapInfo, javax.swing.JLayeredPane.MODAL_LAYER);

        getContentPane().add(jLayeredPaneMain, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents
    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
		jCheckBoxMenuItem_external.setSelected(false);
		this.switchExternal(jCheckBoxMenuItem_external.isSelected());
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jCheckBoxMenuItem_externalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxMenuItem_externalActionPerformed
		this.switchExternal(jCheckBoxMenuItem_external.isSelected());
    }//GEN-LAST:event_jCheckBoxMenuItem_externalActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
		this.goToReplayCentre();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButtonLostReplayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLostReplayActionPerformed
		this.goToReplayCentre();
    }//GEN-LAST:event_jButtonLostReplayActionPerformed

    private void jMenuItem_editLevelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_editLevelActionPerformed
		context.setGameState(HexTD.GameState.editing);
		this.setUI();
    }//GEN-LAST:event_jMenuItem_editLevelActionPerformed

    private void jMenuItem_ReplayCenterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_ReplayCenterActionPerformed
		this.goToReplayCentre();
    }//GEN-LAST:event_jMenuItem_ReplayCenterActionPerformed

    private void jCheckBoxMenuItem_backgroundStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jCheckBoxMenuItem_backgroundStateChanged
		this.gameBoard.setDrawBackground(jCheckBoxMenuItem_background.isSelected());
    }//GEN-LAST:event_jCheckBoxMenuItem_backgroundStateChanged

    private void jMenuItem_restartLevelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_restartLevelActionPerformed
		reStartLevel();
    }//GEN-LAST:event_jMenuItem_restartLevelActionPerformed

    private void jButton_wonNextMapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_wonNextMapActionPerformed
		nextLevel();
    }//GEN-LAST:event_jButton_wonNextMapActionPerformed

    private void jButtonLostTryAgainActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLostTryAgainActionPerformed
		reStartLevel();
    }//GEN-LAST:event_jButtonLostTryAgainActionPerformed

    private void jCheckBox_fastForwardStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jCheckBox_fastForwardStateChanged
		this.gameLoop.setFastForward(jCheckBox_fastForward.isSelected());
}//GEN-LAST:event_jCheckBox_fastForwardStateChanged

    private void jButton_menuMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton_menuMousePressed
		jPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
    }//GEN-LAST:event_jButton_menuMousePressed

    private void jMenuItem_exitLevelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_exitLevelActionPerformed
		gotoSpLevelSelection();
    }//GEN-LAST:event_jMenuItem_exitLevelActionPerformed

    private void jCheckBox_autoLaunchStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jCheckBox_autoLaunchStateChanged
		this.autoLaunch = jCheckBox_autoLaunch.isSelected();
    }//GEN-LAST:event_jCheckBox_autoLaunchStateChanged

    private void jButton_nextWaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_nextWaveActionPerformed
		this.context.tryNextWave();
    }//GEN-LAST:event_jButton_nextWaveActionPerformed

    private void jButton_postScoreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_postScoreActionPerformed
		this.postScore();
    }//GEN-LAST:event_jButton_postScoreActionPerformed

    private void jCheckBoxMenuItem_qualityActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxMenuItem_qualityActionPerformed
		this.gameBoard.setQualityHigh(jCheckBoxMenuItem_quality.isSelected());
    }//GEN-LAST:event_jCheckBoxMenuItem_qualityActionPerformed

private void jButtonMPActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonMPActionPerformed
	this.context.setGameState(GameState.mpConnect);
	jPanelNetConnection.sendLine(MessageChannelJoin.formatMessage(0));
}//GEN-LAST:event_jButtonMPActionPerformed

private void jButtonSPActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSPActionPerformed
	context.setLocalPlayerId(0);
	context.setGameState(GameState.spSelecting);
	setUI();
}//GEN-LAST:event_jButtonSPActionPerformed

private void jButtonWonLobbyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonWonLobbyActionPerformed
	jPanelNetConnection.exitGame();
}//GEN-LAST:event_jButtonWonLobbyActionPerformed

private void jButtonLostLobbyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLostLobbyActionPerformed
	jPanelNetConnection.exitGame();
}//GEN-LAST:event_jButtonLostLobbyActionPerformed

private void jMenuItemHomeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemHomeActionPerformed
	gotoMainMenu();
}//GEN-LAST:event_jMenuItemHomeActionPerformed

private void jCheckBoxPauseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxPauseActionPerformed
	setPause(jCheckBoxPause.isSelected(), true);
}//GEN-LAST:event_jCheckBoxPauseActionPerformed

private void jToggleButtonFullScreenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButtonFullScreenActionPerformed
	switchExternal(jToggleButtonFullScreen.isSelected());
}//GEN-LAST:event_jToggleButtonFullScreenActionPerformed

private void jCheckBoxMenuItemAutoQualityActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxMenuItemAutoQualityActionPerformed
	gameBoard.setAutoQuality(jCheckBoxMenuItemAutoQuality.isSelected());
	jCheckBoxMenuItem_quality.setEnabled(!jCheckBoxMenuItemAutoQuality.isSelected());
}//GEN-LAST:event_jCheckBoxMenuItemAutoQualityActionPerformed

private void formComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentResized
	fixSize();
}//GEN-LAST:event_formComponentResized

private void jLayeredPaneMainComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_jLayeredPaneMainComponentResized
	fixSize();
}//GEN-LAST:event_jLayeredPaneMainComponentResized

private void jButtonReconnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonReconnectActionPerformed
	jPanelNetConnection.startClient();
}//GEN-LAST:event_jButtonReconnectActionPerformed

private void jButtonLoadKeymapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLoadKeymapActionPerformed
	jFrameKeymap.setVisible(false);
	String keymapText = jTextPane_outputKeymap.getText();
	keyMap = Keymap.loadKeyMap(keymapText);
}//GEN-LAST:event_jButtonLoadKeymapActionPerformed

private void jMenuItemKeymapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemKeymapActionPerformed
	jTextPane_outputKeymap.setText(keyMap.printKeymap());
	jFrameKeymap.setVisible(true);
	jFrameKeymap.pack();
}//GEN-LAST:event_jMenuItemKeymapActionPerformed

private void jButtonLostChooseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLostChooseActionPerformed
	gotoSpLevelSelection();
}//GEN-LAST:event_jButtonLostChooseActionPerformed

private void jButtonLostMainActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLostMainActionPerformed
	gotoMainMenu();
}//GEN-LAST:event_jButtonLostMainActionPerformed

private void jButtonWonChooseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonWonChooseActionPerformed
	gotoSpLevelSelection();
}//GEN-LAST:event_jButtonWonChooseActionPerformed

private void jButtonWonMainActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonWonMainActionPerformed
	gotoMainMenu();
}//GEN-LAST:event_jButtonWonMainActionPerformed

private void jButtonReconnect1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonReconnect1ActionPerformed
	jPanelNetConnection.startClient();
}//GEN-LAST:event_jButtonReconnect1ActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private hextd.util.colorSelection colors;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButtonLoadKeymap;
    private javax.swing.JButton jButtonLostChoose;
    private javax.swing.JButton jButtonLostLobby;
    private javax.swing.JButton jButtonLostMain;
    private javax.swing.JButton jButtonLostReplay;
    private javax.swing.JButton jButtonLostTryAgain;
    private javax.swing.JButton jButtonMP;
    private javax.swing.JButton jButtonReconnect;
    private javax.swing.JButton jButtonReconnect1;
    private javax.swing.JButton jButtonSP;
    private javax.swing.JButton jButtonWonChoose;
    private javax.swing.JButton jButtonWonLobby;
    private javax.swing.JButton jButtonWonMain;
    private javax.swing.JButton jButton_menu;
    private javax.swing.JButton jButton_nextWave;
    private javax.swing.JButton jButton_postScore;
    private javax.swing.JButton jButton_wonNextMap;
    private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItemAutoQuality;
    private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItem_background;
    private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItem_external;
    private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItem_quality;
    private javax.swing.JCheckBox jCheckBoxPause;
    private javax.swing.JCheckBox jCheckBox_autoLaunch;
    private javax.swing.JCheckBox jCheckBox_fastForward;
    private javax.swing.JCheckBox jCheckBox_replayPublic;
    private javax.swing.JFrame jFrameKeymap;
    private javax.swing.JFrame jFrame_fullscreen;
    private javax.swing.JInternalFrame jInternalFrameMapInfo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabelConnectionStatus1;
    private javax.swing.JLabel jLabelConnectionStatus2;
    private javax.swing.JLabel jLabelFinalScore;
    private javax.swing.JLabel jLabelFps;
    private hextd.util.BlinkingLabel jLabelGameTitle;
    private javax.swing.JLabel jLabelVersion;
    private javax.swing.JLabel jLabel_debug;
    private javax.swing.JLabel jLabel_submitFeedback;
    private javax.swing.JLayeredPane jLayeredPaneMain;
    private javax.swing.JMenuItem jMenuItemHome;
    private javax.swing.JMenuItem jMenuItemKeymap;
    private javax.swing.JMenuItem jMenuItem_ReplayCenter;
    private javax.swing.JMenuItem jMenuItem_editLevel;
    private javax.swing.JMenuItem jMenuItem_exitLevel;
    private javax.swing.JMenuItem jMenuItem_restartLevel;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanelBadMap;
    private javax.swing.JPanel jPanelConsole;
    private javax.swing.JPanel jPanelConsoleChannelList;
    private hextd.UI.PanelEditor jPanelConsoleEditor;
    private javax.swing.JPanel jPanelConsoleGameInfo;
    private javax.swing.JPanel jPanelConsoleHomeTowerPanel;
    private hextd.UI.PanelLevelSelector jPanelConsoleLevelSelector;
    private hextd.UI.PanelReplayControls jPanelConsoleReplayControls;
    private hextd.UI.PanelTowerInfo jPanelConsoleTowerInfo;
    private hextd.UI.PanelTowerSelector jPanelConsoleTowerSelector;
    private hextd.UI.PanelWaveInfo jPanelConsoleWaveInfo;
    private javax.swing.JPanel jPanelGameButtons;
    private hextd.util.ImagePanel jPanelGameStarts2;
    private javax.swing.JPanel jPanelMapEnds;
    private hextd.UI.PanelNetConnection jPanelNetConnection;
    private javax.swing.JPanel jPanelPlay;
    private javax.swing.JPanel jPanelSubmits;
    private javax.swing.JPanel jPanel_GameLost;
    private javax.swing.JPanel jPanel_GameWon;
    private javax.swing.JPanel jPanel_board;
    private javax.swing.JPanel jPanel_externalMessage;
    private javax.swing.JPanel jPanel_gamePanel;
    private javax.swing.JPanel jPanel_replayEnded;
    private javax.swing.JPanel jPanel_submitScore;
    private javax.swing.JPopupMenu jPopupMenu;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPaneKeymap;
    private javax.swing.JTextField jTextField_postUserName;
    private javax.swing.JTextPane jTextPaneLevelInfo;
    private javax.swing.JTextPane jTextPane_outputKeymap;
    private javax.swing.JToggleButton jToggleButtonFullScreen;
    // End of variables declaration//GEN-END:variables
}
